<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<?php
include_once("php/dbconfig.php");
//header("Content-Type: text/html;charset=uft-8");
include_once("admin/cfg/user.php");

$gUid = new CalendarUser();
$login_authenticated_id = $gUid->isAuthenticatedUser();
$login_admin_id = $gUid->isAdminUser();

?>
<head id="Head1">
    <title>	My Calendar </title>
    
    <meta http-equiv="Content-Type" content="text/html;charset=UTF-8"/>
    <link href="css/dailog.css" rel="stylesheet" type="text/css" />
    <link href="css/calendar.css" rel="stylesheet" type="text/css" /> 
    <link href="css/dp.css" rel="stylesheet" type="text/css" />   
    <link href="css/alert.css" rel="stylesheet" type="text/css" /> 
    <link href="css/main.css" rel="stylesheet" type="text/css" /> 
    
    <script src="src/jquery.js" type="text/javascript"></script>  
    
    <script src="src/Plugins/Common.js" type="text/javascript"></script>    
    <script src="src/Plugins/datepicker_lang_HK.js" type="text/javascript"></script>     
    <script src="src/Plugins/jquery.datepicker.js" type="text/javascript"></script>

    <script src="src/Plugins/jquery.alert.js" type="text/javascript"></script>    
    <script src="src/Plugins/jquery.ifrmdailog.js" defer="defer" type="text/javascript"></script>
    <script src="src/Plugins/wdCalendar_lang_HK.js" type="text/javascript"></script>    
    <script src="src/Plugins/jquery.calendar.js" type="text/javascript"></script>   
    
    <script type="text/javascript">
 function ChatHidden() {
           document.getElementById("eventdetaildiv").style.display = "none";
           document.getElementById("movedivid").style.height = "26px";
       }
       function ChatShow() {
           document.getElementById("movedivid").style.display = "block";
           document.getElementById("movedivid").style.height = "400px";
           document.getElementById("eventdetaildiv").style.display = "block";
       }
       function ChatClose() {
           document.getElementById("movedivid").style.display = "none";
       }
 
       var drag_ = false
       var D = new Function('obj', 'return document.getElementById(obj);');
       var oevent = new Function('e', 'if (!e) e = window.event;return e');
       function Move_obj(obj) {
           var x, y;
           D("main").onmousedown = function(e) {
               drag_ = true;
               with (this) {
                   D("main").style.position = "absolute";
                   var temp1 = D("movedivid").offsetLeft; //距离左边的初始值
                   var temp2 = D("movedivid").offsetTop;  //距离顶边的初始值
                   x = oevent(e).clientX;
                   y = oevent(e).clientY;
                   document.onmousemove = function(e) {
                       if (!drag_) {
                           return false;
                       }
                       with (this) {
                           D("movedivid").style.left = temp1 + oevent(e).clientX - x + "px"; //层离左边距的像素
                           D("movedivid").style.top = temp2 + oevent(e).clientY - y + "px"; //层离顶部距的像素
                       }
                   }
               }
               document.onmouseup = new Function("drag_=false");
           }
       }  
   
   
               function clickET(etdivid)
            {
                alert(etdivid);
            }
    
        $(document).ready(function() {     
           //var view="week";
           var  view = "month";
           
            var DATA_FEED_URL = "php/datafeed.php";
            var op = {
                view: view,
                theme:3,
                showday: new Date(),
                EditCmdhandler:Edit,
                DeleteCmdhandler:Delete,
                ViewCmdhandler:View,    
                onWeekOrMonthToDay:wtd,
                onBeforeRequestData: cal_beforerequest,
                onAfterRequestData: cal_afterrequest,
                onRequestDataError: cal_onerror, 
                autoload:true,
               
                readonly: <?php if($login_authenticated_id) {echo 'false';}else{echo 'true';}; ?>,//true,
                enableDrag: <?php if($login_admin_id) {echo 'true';}else{echo 'false';}; ?>,//false,
                url: DATA_FEED_URL + "?method=list",  
                //quickAddUrl: DATA_FEED_URL + "?method=add", 
                quickUpdateUrl: DATA_FEED_URL + "?method=update",
                quickDeleteUrl: DATA_FEED_URL + "?method=remove"       
            };
            var $dv = $("#calhead");
            var _MH = document.documentElement.clientHeight-50;
            var dvH = $dv.height() + 2;
            op.height = _MH - dvH;
            op.eventItems =[];
            
            var p = $("#gridcontainer").bcalendar(op).BcalGetOp();
            if (p && p.datestrshow) {
                $("#txtdatetimeshow").text(p.datestrshow);
            }
            $("#caltoolbar").noSelect();
            
            $("#hdtxtshow").datepicker({ picker: "#txtdatetimeshow", showtarget: $("#txtdatetimeshow"),
            onReturn:function(r){                          
                            var p = $("#gridcontainer").gotoDate(r).BcalGetOp();
                            if (p && p.datestrshow) {
                                $("#txtdatetimeshow").text(p.datestrshow);
                            }
                     } 
            });
            function cal_beforerequest(type)
            {
                var t="Loading data...";
                switch(type)
                {
                    case 1:
                        t="Loading data...";
                        break;
                    case 2:                      
                    case 3:  
                    case 4:    
                        t="The request is being processed ...";                                   
                        break;
                }
                $("#errorpannel").hide();
                $("#loadingpannel").html(t).show();    
            }
            function cal_afterrequest(type)
            {
                switch(type)
                {
                    case 1:
                        $("#loadingpannel").hide();
                        break;
                    case 2:
                    case 3:
                    case 4:
                        $("#loadingpannel").html("Success!");
                        window.setTimeout(function(){ $("#loadingpannel").hide();},2000);
                    break;
                }              
                //$("#showmonthbtn").click();
                $("#caltoolbar div.fcurrent").each(function() {
                    $(this).removeClass("fcurrent");
                })
                $(this).addClass("fcurrent");
                var p = $("#gridcontainer").swtichView("month").BcalGetOp();
                if (p && p.datestrshow) {
                    $("#txtdatetimeshow").text(p.datestrshow);
                }
            }
            function cal_onerror(type,data)
            {
                $("#errorpannel").show();
            }

            function Edit(data)
            {
               var eurl="edit.php?id={0}&start={2}&end={3}&isallday={4}&title={1}";   
                if(data)
                {
                    var url = StrFormat(eurl,data);
                    OpenModelWindow(url,{ width: 600, height: 400, caption:"管理事件",onclose:function(){
                       $("#[id^=show_bbit_cal_event]").remove();
                       $("#gridcontainer").reload();
                    }});
                }
            }    
            function View(data)
            {
//                var str = "";
//                $.each(data, function(i, item){
//                    str += "[" + i + "]: " + item + "\n";
//                });
//                alert(str); 
                
                //alert(data.length);
                if(data[24] == 1)
                {
                    var detailUrl="detail.php?id=" + data[0]; 
                    OpenModelWindow(detailUrl,{ width: 600, height: 400, caption:"事件細節",onclose:function(){
                    $("#gridcontainer").reload();
                    }});
                }

                
//                $("#showDescriptiondiv").remove();
//                
//                $("#eventfestivalspan").empty;
//                 if(data[21] != null && $.trim(data[21]) != "")
//                     {
//                         $("#eventfestivalspan").append("[所屬節目]: ").append(data[21]);
//                     }
//                     
//                $("#eventtitlespan").empty();
//                $("#eventtitlespan").append("[活動名稱]: ").append(data[1]);
//                
//                $("#eventdatetimespan").empty();
//                $("#eventdatetimespan").append("[時間]: ").append(data[24]);
//                
//                $("#eventeventtypespan").empty();
//                $("#eventeventtypespan").append("[類型]: ").append(data[17]);
//            
//                $("#eventcityspan").empty();
//                $("#eventcityspan").append("[城市]: ").append(data[18]);
//                
//                $("#eventvenuespan").empty();
//                $("#eventvenuespan").append("[場地]: ").append(data[16]);
//                
//                $("#eventvenueadrspan").empty();
//                if(data[22] != null && $.trim(data[22]) != "")
//                     {
//                         $("#eventvenueadrspan").append("[地址]: ").append(data[22]);
//                     }
//                     
//                 $("#eventvenueurlspan").empty();
//                 if(data[23] != null && $.trim(data[23]) != "")
//                     {
//                         $("#eventvenueadrspan").append("[網站]: ").append(data[23]);
//                     }
//                     
//                $("#eventdesspan").empty();
//                 if(data[10] != null && $.trim(data[11]) != "")
//                     {
//                         $("#eventdesspan").append("[詳細介紹]: ").append(data[11]);
//                     }
//    
//                $("#eventurlspan").empty();
//                if(data[10] != null && $.trim(data[10]) != "")
//                {
//                    var href = "AMCNN文章";
//                    $("#eventurlspan").append("[延伸閱讀]: ")
//                    .append(href.link(data[10]));
//                    $("#eventurlspan").attr("class","hrefhighlink");
//                    
//                }
//                
//                $("#eventimgspan").empty();
//                $("#eventimgspan").children().remove();
//                if(data[12] !=null && $.trim(data[12]) !="")
//                {
//                    //<embed src="时钟地址" width="宽度" height="高度" type="application/x-shockwave-flash"wmode="transparent">
//                     var pictures = data[12].split(";");
//                     for(var i =1; i<pictures.length; i++)
//                     {
//                         if($.trim(pictures[i]).length > 0)
//                         {
//                            var tagImg = "<img src='" + pictures[i] + "' \/>";
//                            $("#eventimgspan").append("[圖片]: ")
//                            .append(tagImg)
//                            .append("<br></br>");
//                         }
//                        
//                     }
//                    
//                }
//                
//                $("#eventflashspan").empty();
//                $("#eventflashspan").children().remove();
//                if(data[19] !=null && $.trim(data[19]) !="")
//                {
//                     var flashes =  data[19].split(";");
//                      for(var i =0; i<flashes.length; i++)
//                     {
//                        var tagflash = "<embed src='" + flashes[i] + "' type=\"application/x-shockwave-flash\" wmode=\"transparent\">";
//                        $("#eventflashspan").append("[多媒體]: ")
//                        .append(tagflash)
//                        .append("<br\/>");
//                     }
//                }  
//                $("#movedivid").show();
            }    
            function Delete(data,callback)
            {           
                
                $.alerts.okButton="確定";  
                $.alerts.cancelButton="取消";  
                hiConfirm("你確定删除當前事件嗎？", '確定',function(r){ r && callback(0);});           
            }
            function wtd(p)
            {
               if (p && p.datestrshow) {
                    $("#txtdatetimeshow").text(p.datestrshow);
                }
                $("#caltoolbar div.fcurrent").each(function() {
                    $(this).removeClass("fcurrent");
                })
                $("#showdaybtn").addClass("fcurrent");
            }
            
            function clickET(etdivid)
            {
                alert(etdivid);
            }
            
            //to show day view
            $("#showdaybtn").click(function(e) {
                //document.location.href="#day";
                $("#caltoolbar div.fcurrent").each(function() {
                    $(this).removeClass("fcurrent");
                })
                $(this).addClass("fcurrent");
                var p = $("#gridcontainer").swtichView("day").BcalGetOp();
                if (p && p.datestrshow) {
                    $("#txtdatetimeshow").text(p.datestrshow);
                }
            });
            
 
            //to show week view
            $("#showweekbtn").click(function(e) {
                //document.location.href="#week";
                $("#caltoolbar div.fcurrent").each(function() {
                    $(this).removeClass("fcurrent");
                })
                $(this).addClass("fcurrent");
                var p = $("#gridcontainer").swtichView("week").BcalGetOp();
                if (p && p.datestrshow) {
                    $("#txtdatetimeshow").text(p.datestrshow);
                }

            });
            //to show month view
            $("#showmonthbtn").click(function(e) {
                //document.location.href="#month";
                $("#caltoolbar div.fcurrent").each(function() {
                    $(this).removeClass("fcurrent");
                })
                $(this).addClass("fcurrent");
                var p = $("#gridcontainer").swtichView("month").BcalGetOp();
                if (p && p.datestrshow) {
                    $("#txtdatetimeshow").text(p.datestrshow);
                }
    
            });
            
            if($("#slctcity").find("option").length == 1)
            {
                    
                    $.post(DATA_FEED_URL + "?method=getAllCities",
                    function (data){ 
                        $.each(data.cities,function(index, value){                        
                        $("#slctcity").append('<option value = ' 
                                          + value[0] 
                                          +'>'
                                          + value[1]
                                          + '</option>');                  
                    }); 
                        
                        },
                    "json");
                }
          
           $.each($("#[id^=show_event_type_btn_]"),function(index,value){
               //alert($(this).find("input").val().split("$")[0]);
               var evet_type_index = $(this).find("input").val().split("$")[0];
               var color_value_id_jq = "#" + "select_event_type_color_input_hidden_" + evet_type_index;
               var current_event_type_id_jq = "#" + "show_event_type_btn_" + evet_type_index;

               var current_color_array = $(color_value_id_jq).val().split("$");
               if(current_color_array.length > 1 && current_color_array[1].search(/#/) == 0)
                   {
                       $(current_event_type_id_jq)//.css("color",current_color_array[1])
                       //.css("font-weight","700").css("font-size","14px");
                       .css("background",current_color_array[1]);
                   }
           });
           
           
            $("#[id^=show_event_type_btn_]").click(function(e){
                
                var select_value_array =  $(this).find("input").val().split("$");

                $("#slcteventtype").val(select_value_array[0]);
//                 $("#eventtypecaltoolbar div.fcurrent").each(function() {
//                    $(this).removeClass("fcurrent");
//                })
                
                $.each($("#[id^=show_event_type_btn_]"),function(index,value){
                    var evet_type_index = $(this).find("input").val().split("$")[0];
                    //alert ($(this).find("input").val())
                    if(select_value_array[0] != evet_type_index)
                        {
                            //$(this).addClass("fbutton");
                            //$(this).css("color","#000").css("background","none");
                            $(this).css("color","#000").css("background",$(this).find("input").val().split("$")[1]);
                        }
                });
                
                
                $(this).addClass("fcurrent");
                if(select_value_array[0] != 0)
                    {
                $(this).css("color",select_value_array[1])//.css("font-weight","700").css("font-size","14px")
                .css("background","#808080");
                    }
//                    else
//                        {
//                            $(this).addClass("fbutton");
//                            $(this).css("color","#000").css("background","none");
//                        }
                $("#gridcontainer").reload();
            });
            
            $("#showreflashbtn").click(function(e){
                $("#gridcontainer").reload();
            });

            
            $("#slctcity").change(function(e)
            {
                //ajax call to get the venues assciation with city
                $.post(DATA_FEED_URL + "?method=getVenuesByCityId",
                {cityid: $("#slctcity").val()},
                function (data){
                    
                    //if(data.error != null)
                    //{
                       //var selectcitytext = $("#slctcity").find("option:selected").text();
                       var selectcityval = $("#slctcity").find("option:selected").val();
                       
                       
                       $("#slctvenue")
                       //.find('option')
                       //.remove()
                       //.end()
                       .empty();
                       
                       if(selectcityval != 0)
                       {
                           var selectcitytext = $("#slctcity").find("option:selected").text();
                           $("#slctvenue")
                           .append('<option value="0">選擇'+selectcitytext+'場地</option>');
                       }
                       else
                       {
                           $("#slctvenue")
                           .append('<option value="0">所有場地</option>');    
                       }

                    $.each(data.venues,function(index, value){
                    $("#slctvenue").append('<option value = ' 
                                          + value[0] 
                                          +'>'
                                          + value[1]
                                          + '</option>');                 
                    });},
                "json");
                
                
                
                $("#gridcontainer").reload();
            });
            
            $("#slctvenue").change(function(e)
            {       
                $("#gridcontainer").reload();
            });
            
            //Add a new event
            $("#faddbtn").click(function(e) {
                var url ="edit.php?id=";
                OpenModelWindow(url,{ width: 500, height: 400, caption: "新建事件",onclose:function(){
                       $("#gridcontainer").reload();}});
            });
            //go to today
            $("#showtodaybtn").click(function(e) {
                var p = $("#gridcontainer").gotoDate().BcalGetOp();
                if (p && p.datestrshow) {
                    $("#txtdatetimeshow").text(p.datestrshow);
                }


            });
            //previous date range
            $("#sfprevbtn").click(function(e) {
                var p = $("#gridcontainer").previousRange().BcalGetOp();
                if (p && p.datestrshow) {
                    $("#txtdatetimeshow").text(p.datestrshow);
                }

            });
            //next date range

            $("#sfnextbtn").click(function(e) {
                var p = $("#gridcontainer").nextRange().BcalGetOp();
                if (p && p.datestrshow) {
                    $("#txtdatetimeshow").text(p.datestrshow);
                }
            });
            
           $("#syscfglink").append("[系統配置...]  ".link("admin/cfg/cfg.php"));
           $("#syscfglink").attr("class","hrefhighlink");   
        });
    </script> 
    
    
   
</head>
<body>
    
    <div>

      <div id="calhead" style="padding-left:1px;padding-right:1px;"> 
           
            <div class="cHead"></div>
<!--            <div id="loadingpannel" class="ptogtitle loadicon" style="display: none;">下載數據中...</div>
             <div id="errorpannel" class="ptogtitle loaderror" style="display: none;">抱歉,不能更新到你的數據,請重試</div>-->
            </div>          
            
            <div id="caltoolbar" class="ctoolbar">
             <div id="loadingpannel" class="ptogtitle loadicon" style="display: none;">下載數據中...</div>
             <div id="errorpannel" class="ptogtitle loaderror" style="display: none;">抱歉,不能更新到你的數據,請重試</div>
             
           
             
              <?php if($login_authenticated_id)
                  {
                    echo '<div class="btnseparator"></div>'
                    .'<div id="faddbtn" class="fbutton">'
                    .'<div><span title="Click to Create New Event" class="addcal">'
                    .'新日程</span></div></div>';
                  }
              ?>
<!--             jace start-->
<!--             <div class="btnseparator"></div>
                <div id="showdaybtn" class="fbutton">
                    <div><span title='Day' class="showdayview">天</span></div>
                </div>
                  <div  id="showweekbtn" class="fbutton fcurrent">
                    <div><span title='Week' class="showweekview">周</span></div>
                </div>-->
                   <div class="btnseparator"></div>
                  <div  id="showmonthbtn" class="fbutton">
                    <div><span title='Month' class="showmonthview">月</span></div>
                </div>
<!--             jace end-->             

            <div class="btnseparator"></div>
              <div  id="showreflashbtn" class="fbutton">
                <div><span title='Refresh view' class="showdayflash"><!--Refresh-->刷新</span></div>
                </div>
             <div class="btnseparator"></div>
            <div id="sfprevbtn" title="Prev"  class="fbutton">
              <span class="fprev"></span>

            </div>
            <div id="sfnextbtn" title="Next" class="fbutton">
                <span class="fnext"></span>
            </div>
            <div class="fshowdatep fbutton">
                    <div>
                        <input type="hidden" name="txtshow" id="hdtxtshow" />
                        <span id="txtdatetimeshow"><!--Loading-->選擇日期</span>

                    </div>
            </div>  
             <div class="btnseparator"></div>        
             <?php
                 echo '<select name = "slctcity" id = "slctcity">'; 
                 echo '<option value= "0" >選擇城市</option>';               
                 echo '</select>'; 
             ?> 
            
              <?php
                 echo '<select name = "slctvenue" id ="slctvenue" >';
                 echo '<option value= "0" >選擇場地</option>';
                 echo '</select>'; 
              ?> 
          
              <?php 
                $ver='v1.4.5';//顯示代碼版本信息
                if($login_admin_id)
                {
                   echo '<div class="rbutton">';
                   echo '<span id=syscfglink>'
                    .'</span>';//</div>';
                   echo $ver.'</div>';
                   // echo '<span id=syscfglink>'
                   // .'</span></div>';
                }
                //else {
                //echo '<div class="rbutton">';
                //echo $ver.'</div>';
                //}
              ?>
            <div class="clear"></div>
            
              
            
            </div>
         <div id="eventtypecaltoolbar" class="ctoolbar">
         <?php 
            echo '<input id="slcteventtype" type="hidden" value="0" />';
            echo '<div id="show_event_type_btn_0" class="fbutton">';
            echo '<div>';
            echo '<span  title="所有類型" class="addcal">所有類型</span>';
            echo '<input id="select_event_type_color_input_hidden_0" type="hidden" value="0" />';
            echo ' </div>';
            echo ' </div>';
            $db = new DBConnection();
            $db->getConnection();
            $sql = "select * from `event_type` where `event_type`.`delete_flag` = 0";
            $result = mysql_query($sql);       
            while($row = mysql_fetch_array($result))  
            {
                echo '<div class="btnseparator"></div>';
                echo '<div  id="show_event_type_btn_'."{$row['etid']}".'" class="fbutton">';
                echo '<div><span class="showeventtype">'."{$row['name_zh_hk']}".'</span></div>';
                echo '<input id="select_event_type_color_input_hidden_'
                ."{$row['etid']}".'" type="hidden" value="'."{$row['etid']}"."$"."{$row['color_mark']}".'" />';
                echo '</div>';
            }         
        ?>   
            </div>      
          
      </div>
  
  </div>
    <div class="clear"></div>
      <div style="padding:1px;">

        <div class="t1 chromeColor">
            &nbsp;</div>
        <div class="t2 chromeColor">
            &nbsp;</div>
        <div id="dvCalMain" class="calmain printborder">
            <div id="gridcontainer" style="overflow-y: visible;">
            </div>
        </div>
        <div class="t2 chromeColor">

            &nbsp;</div>
        <div class="t1 chromeColor">
            &nbsp;
        </div>   
        </div>
     
  </div>
 
    
    
    

        
        <div id="movedivid">
            <div id="main" onmousedown="Move_obj('movedivid')"> 
                <div id="eventdetailhead">
                    <strong style="color: #FFFFFF;">&nbsp;事件細節</strong></div>
 
                <div id="eventdetailmove" class ="cc-close" onclick ="ChatClose()"></div>
<!--                <div id="eventdetailmdisplay">
                    <strong style="color: #FFFFFF"><a href="#" onclick="ChatShow();">+</a>&nbsp;</strong></div>
                <div id="eventdetailmhide" >
                    <a href="#" onclick="ChatHidden();"><strong style="color: #FFFFFF;">—&nbsp;</strong></a></div>-->
           </div>
            <div id="eventdetaildiv">
<!--             <label>                    
                   <span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                   </span>
               </label><br/>-->
               
               <div id="eventfestivalspan"></div>
               <div id="eventtitlespan"></div>
               <div id="eventdatetimespan"></div>
               <div id="eventeventtypespan"></div>
               <div id="eventcityspan"></div>
               <div id="eventvenuespan"></div>
               <div id="eventvenueadrspan"></div>
               <div id="eventvenueurlspan"></div>
               <div id="eventdesspan"></div>
               <div id="eventurlspan"> </div>
               <div id="eventimgspan"></div> 
               <div id="eventflashspan"></div>

            </div>
        </div>
    
</body>
</html>

